(ns cljsso-client.config
  (:require [clojure.edn :as e]
            [clojure.java.io :as io]
            [clojure.pprint :refer [pprint]])
  (:import  [java.util UUID]))

(defonce cfg
  "sso-client-config.edn")

(def default-conf
  {;; SSO configuration
   :sso-key "1432ksaks/*"
   :sso-servers
   [{:ip "127.0.0.1" :host "https://sso.com" :id "0" :name "sso server" :login-url "https://sso.com/login" :logout-url "https://sso.com/logout" :ticket-validate-url "https://sso.com/validate"}]

   ;; 本主机的域名
   :app-host "sso1.com"
   :scheme "https"
   ;; 接受SSL个人证书
   :insecure? true
   :port 7777
   })

(defn read-props
  "Read properties from config, if not found create with default vals"
  []
  (if (.exists (io/file cfg))
    (e/read-string (slurp cfg))
    (with-open [o (io/writer cfg)]
      (prn "config.edn not found, default created.")
      (pprint default-conf o)
      default-conf)))


(def props
  (read-props))
